package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Order;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    //依赖注入service层
    @Autowired
    private OrderService orderService;

    /**
     * 提交订单页面
     * Request URL: http://localhost:8081/order/submit
     * Request Method: POST
     */
    @PostMapping("/submit")
    public ResultInfo submit(@RequestBody Order order){ //接收在请求体中的参数
        //1.调用service层
        orderService.submit(order);
        //2.返回响应
        return ResultInfo.success();
    }

    /**
     * 历史订单页面
     * Request URL: http://localhost:8081/order/userPage?page=1&pageSize=5
     * Request Method: GET
     */
    @GetMapping("/userPage")
    public ResultInfo historyOrder(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum,
                                   @RequestParam(name = "pageSize",defaultValue = "pageSize") Integer pageSize){    //接收分页参数
        //1.调用service层
        Page<Order> page = orderService.findByPage(pageNum,pageSize);
        //2.返回响应
        return ResultInfo.success(page);
    }
}
